Skip to content

Refuse invalid persona moves before joining outstanding decode - #152

Open
joelteply wants to merge 1 commit into
fable/kv-stream-blocksfrom
codex/runtime-persona-streams-20261118
Open

joelteply wants to merge 1 commit into
fable/kv-stream-blocksfrom
codex/runtime-persona-streams-20261118

Conversation

@joelteply

Copy link
Copy Markdown

Stacked on #147. Move the context synchronization to the accepted commit boundary for native save and load. The validation phase checks host metadata and prepares destination storage. A refusal can now return while decode remains queued. Accepted transfers still synchronize before accessing device rows. This is a narrow fault-path change. Dynamic stream growth and overlapped successful transfers remain open.

Windows MSVC static Release, CPU, two threads: test-persona-blocks passed on Qwen2.5-0.5B Q4_K_M and Qwen3.5-0.8B Q8_0 hybrid. Both resident continuations were byte-identical. The regression assertion compares completed prompt tokens across a refused save while decode is queued. No production timing claim.

@joelteply

Copy link
Copy Markdown
Author

Controlled fault replay: identical test source, base a88f255 plus the new assertion exits 1 specifically on the refused save joining the pending decode; head dd543aa exits 0 with byte-identical resident continuations. Windows CPU Qwen2.5-0.5B Q4_K_M, two threads. Accepted-move control, alternating base/head/head/base, 128-token prompt, 1.6 MB state: base save 0.62–0.64 ms/load 0.15 ms, head save 0.62–0.76 ms/load 0.14–0.15 ms. Sampled peak working set approximately 509 MB; both following tokens byte-identical on every run. The demonstrated benefit is the avoided join on refusal. GPU concurrency and production throughput remain unmeasured.

@joelteply joelteply left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fable review at dd543aa: approve the change.

Claim verified by reading the head:

  • persona_check_save (src/llama-kv-cache.cpp:1286) and persona_check_load (:1342) are const. They read only host cell metadata (v_cells[..].used_max_p1(), get_used(), seq_pos_max), which a decode updates when it is submitted, so they are valid while that decode is still queued. Save's check sizes only the caller's host vectors.
  • Both commits still synchronize() before ggml_backend_tensor_get / tensor_set on the stream's rows (llama-context.cpp persona_save / persona_load), so an accepted move still fences.
  • The regression is real: n_p_eval only moves inside llama_context::synchronize() (llama-context.cpp:728-746, from n_queued_tokens), and f.prompt decodes without reading logits. An equal counter across the refused save proves the refusal did not synchronize.

Not verified: I did not run it. Your Windows CPU receipts are the run.

Non-blocking: nothing here asserts the accepted path still fences. The byte-identical continuations cover it indirectly; a later card could pin it the same way (the counter moves across an accepted save).

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant